//
//  ResumeWorkCell.m
//  Btpin
//
//  Created by Vic on 2019/3/27.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "ResumeWorkCell.h"

#define BtnTap (7810)

@interface ResumeWorkCell ()
{
    UILabel *titleLbl;
    UILabel *detailLbl;
    UILabel *timeLbl;
    UILabel *contentLbl;
    UIScrollView *scrollView;
    
    NSMutableArray *dataArr;
}
@end

@implementation ResumeWorkCell

- (instancetype)initWithFrame:(CGRect)frame type:(ResumeWorkCellType)type text:(nullable NSString *)text detailText:(nullable NSString *)detailText time:(nullable NSString *)time content:(nullable NSString *)content imgs:(nullable NSArray *)imgs {
    self = [super initWithFrame:frame];
    if (self) {
        dataArr = [NSMutableArray arrayWithCapacity:0];
        [dataArr addObjectsFromArray:imgs];
        [self initUIType:type text:text detailText:detailText time:time content:content imgs:imgs];
    }
    return self;
}
- (void)initUIType:(ResumeWorkCellType)type text:(nullable NSString *)text detailText:(nullable NSString *)detailText time:(nullable NSString *)time content:(nullable NSString *)content imgs:(nullable NSArray *)imgs {
    titleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 15*Scale, self.frame.size.width, 20*Scale) text:text textColor:THEMECOLOR_OF_TEXT_333333 font:Font_15];
    titleLbl.font = FontBold(Font_15);
    [self addSubview:titleLbl];
    
    CGFloat detailHeight = 0.00001;
    if (detailText &&detailText.length) {
        detailLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, EndY(titleLbl), self.frame.size.width, 20*Scale) text:detailText textColor:THEMECOLOR_OF_TEXT_333333 font:Font_13];
        [self addSubview:detailLbl];
        detailHeight = 20*Scale;
    }
    
    timeLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, StartY(titleLbl), self.frame.size.width, 20*Scale) text:time textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    timeLbl.textAlignment = NSTextAlignmentRight;
    [self addSubview:timeLbl];
    
    
    CGFloat contentHeight = [UIToolsControl textHeightWithLineSpacing:(content?content:@"") size:CGSizeMake(self.frame.size.width, MAXFLOAT) font:Font_13]+1;
    contentLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, EndY(titleLbl)+detailHeight+10*Scale, self.frame.size.width, contentHeight) text:(content?content:@"") textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:contentLbl];
    contentLbl.numberOfLines = 0;
    contentLbl.lineBreakMode = NSLineBreakByWordWrapping;
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = LineSpacingHeight;
    contentLbl.attributedText = [[NSAttributedString alloc] initWithString:(content?content:@"") attributes:@{NSFontAttributeName:Font(Font_13), NSParagraphStyleAttributeName:paraStyle}];
    
    if (imgs && imgs.count) {
        scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, ((type == ResumeWorkCellTypeOfOneTextImg)?EndY(contentLbl)-10*Scale:EndY(contentLbl)+10*Scale), self.frame.size.width, 60*Scale)];
        [self addSubview:scrollView];
        for (NSInteger i = 0; i < imgs.count; i++) {
            NSString *imgUrl = imgs[i];
            if (imgUrl && imgUrl.length) {
                UIImageView *imgView = [UIToolsControl initImageViewWithFrame:CGRectMake((60*Scale+10*Scale)*i, 0, 60*Scale, 60*Scale) imageName:nil];
                imgView.backgroundColor = THEMECOLOR_OF_GRAY;
                [scrollView addSubview:imgView];
                [imgView sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
                
                UIButton *btn = [UIToolsControl initButtonWithFrame:CGRectMake((60*Scale+10*Scale)*i, 0, 60*Scale, 60*Scale) imageName:nil target:self action:@selector(btnTap:) title:nil titleColor:nil];
                btn.tag = BtnTap+i;
                [scrollView addSubview:btn];
            }
        }
        scrollView.contentSize = CGSizeMake((60*Scale+10*Scale)*imgs.count, 0);
    }
}
- (void)btnTap:(UIButton *)button {
    NSString *imgUrl = dataArr[button.tag-BtnTap];
    if (imgUrl&&imgUrl.length) {
        [[NSNotificationCenter defaultCenter] postNotificationName:NotificationFor_Resume_LookImg object:nil userInfo:@{@"url":imgUrl}];
    }
}

@end
